package com.sun.controller;


import com.sun.dao.Team;
import com.sun.dao.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MyController {

    @RequestMapping("mytest0")
    public String myTest0(@RequestBody String jsonString){
        System.out.println(jsonString);
        return jsonString;
    }

    @RequestMapping("mytest1")
    public String mytest1(@RequestBody User user){
        System.out.println(user);
        return user.toString();
    }

    @RequestMapping("mytest2")
    public String mytest2(@RequestBody Team team){
        System.out.println(team);
        return team.toString();
    }

    @RequestMapping("mytest3")
    public String mytest3(@RequestBody User user, @RequestParam("token") String token){
        System.out.println(user);
        System.out.println(token);
        return user.toString()+token;
    }

    @RequestMapping("mytest4")
    public String mytest4(@RequestBody User user, @RequestParam("arrays") List<String> arrays){
        System.out.println(user);
        StringBuilder sb = new StringBuilder();
        for(String s : arrays){
            sb.append(s);
            sb.append(";");
            System.out.println(s);
        }

        return user.toString()+"+"+sb.toString();
    }

    @RequestMapping("mytest5")
    public String mytest5(@RequestBody User user1,User user2){
        System.out.println(user1);
        System.out.println(user2);
        return user1.toString() +"\n" + user2.toString();
    }

    @RequestMapping("mytest6")
    public String mytest6(@RequestParam String name,@RequestParam Integer age){
        System.out.println(name+"的年龄为："+age);
        return name+"的年龄为："+age;
    }

}
